package sqldb_helper

import (
	"database/sql"
	_ "lib/mysql"
)

func ConnectDB(dbaddr string) (retDB *sql.DB) {
	var err error
	retDB, err = sql.Open("mysql", dbaddr)
	if err != nil {
		panic(err)
		return nil
	}
	err = retDB.Ping()
	if err != nil {
		panic(err)
		return nil
	}
	return retDB
}

func IsExitTable(db *sql.DB, tableName string) bool {
	row := db.QueryRow("show tables like '" + tableName + "' ")
	var ScanTableName string
	row.Scan(&ScanTableName)
	if ScanTableName == "" {
		return false
	}
	return true
}
